package vistas.ui;
import java.awt.Component;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.AbstractAction;
import javax.swing.GroupLayout;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JTextArea;
import javax.swing.LayoutStyle;
import javax.swing.SwingConstants;

import controladores.ControladorBorrarClienteFrame;
import controladores.ControladorModificarClienteFrame;
import controladores.interfaces.ControladorAdministradorClientes;


/**
 * This code was edited or generated using CloudGarden's Jigloo
 * SWT/Swing GUI Builder, which is free for non-commercial
 * use. If Jigloo is being used commercially (ie, by a corporation,
 * company or business for any purpose whatever) then you
 * should purchase a license for each developer using Jigloo.
 * Please visit www.cloudgarden.com for details.
 * Use of Jigloo implies acceptance of these licensing terms.
 * A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
 * THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
 * LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
 */
public class BorrarClienteFrame extends javax.swing.JInternalFrame {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JLabel lblCuit;
	private JButton btnCancelar;
	private AbstractAction abstractAction1;
	private AbstractAction abstractAction2;
	private JTextArea txtDisplay;
	private JComboBox cmbNroCuit;
	private JButton btnBorrar;

	/**
	 * Auto-generated main method to display this 
	 * JInternalFrame inside a new JFrame.
	 */

	public BorrarClienteFrame() {
		super();
		initGUI();
	}

	private void initGUI() {
		try {
			this.setPreferredSize(new java.awt.Dimension(297, 300));
			this.setBounds(0, 0, 297, 300);
			GroupLayout thisLayout = new GroupLayout((JComponent)getContentPane());
			getContentPane().setLayout(thisLayout);
			setVisible(true);
			this.setTitle("Borrar cliente");
			{
				lblCuit = new JLabel();
				lblCuit.setText("CUIT: ");
			}
			{
				txtDisplay = new JTextArea("Seleccione el CUIT del\ncliente a borrar");
			}
			{
				btnBorrar = new JButton();
				btnBorrar.setText("Borrar");
				btnBorrar.setAction(getAbstractAction2());
			}
			{
				btnCancelar = new JButton();
				btnCancelar.setText("Cancelar");
				btnCancelar.setAction(getAbstractAction1());
			}
			{
//				ComboBoxModel cmbNroCuitModel = 
//						new DefaultComboBoxModel(
//								new String[] { "Item One", "Item Two" });
				cmbNroCuit = new JComboBox();
				cmbNroCuit.setEditable(false);
				ControladorAdministradorClientes controladorClientes = new ControladorBorrarClienteFrame();
				cmbNroCuit.addItem("");
				for(String cuit : controladorClientes.obtenerCUITs()){
					cmbNroCuit.addItem(cuit);
				}
				cmbNroCuit.addActionListener(new ActionListener() {
					
					@Override
					public void actionPerformed(ActionEvent e) {
						// TODO Auto-generated method stub
						ControladorAdministradorClientes controladorCli = new ControladorModificarClienteFrame();
						txtDisplay.setText(controladorCli.obtenerCliente((String)cmbNroCuit.getSelectedItem()).toString());
						/*
						 * Aca hay que meter una llamada al controlador para que segun el elegido
						 * devuelva el cliente y por medio de algun metodo (hay que crearlo), se 
						 * muestre en la textArea una descripcion del cliente que se esta por borrar.
						 */
					}
				});
			}
			thisLayout.setHorizontalGroup(thisLayout.createSequentialGroup()
					.addContainerGap()
					.addGroup(thisLayout.createParallelGroup()
							.addGroup(GroupLayout.Alignment.LEADING, thisLayout.createSequentialGroup()
									.addComponent(btnCancelar, GroupLayout.PREFERRED_SIZE, 124, GroupLayout.PREFERRED_SIZE)
									.addGap(20)
									.addComponent(btnBorrar, GroupLayout.PREFERRED_SIZE, 127, GroupLayout.PREFERRED_SIZE)
									.addGap(0, 0, Short.MAX_VALUE))
									.addGroup(GroupLayout.Alignment.LEADING, thisLayout.createSequentialGroup()
											.addComponent(lblCuit, GroupLayout.PREFERRED_SIZE, 44, GroupLayout.PREFERRED_SIZE)
											.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
											.addComponent(cmbNroCuit, 0, 215, Short.MAX_VALUE))
											.addComponent(txtDisplay, GroupLayout.Alignment.LEADING, 0, 271, Short.MAX_VALUE))
											.addContainerGap());
			thisLayout.setVerticalGroup(thisLayout.createSequentialGroup()
					.addGap(8)
					.addGroup(thisLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
							.addComponent(cmbNroCuit, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, 21, GroupLayout.PREFERRED_SIZE)
							.addComponent(lblCuit, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE))
							.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
							.addComponent(txtDisplay, 0, 202, Short.MAX_VALUE)
							.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
							.addGroup(thisLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
									.addComponent(btnBorrar, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, 22, GroupLayout.PREFERRED_SIZE)
									.addComponent(btnCancelar, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE))
									.addContainerGap());
			thisLayout.linkSize(SwingConstants.HORIZONTAL, new Component[] {btnCancelar, btnBorrar});
			thisLayout.linkSize(SwingConstants.VERTICAL, new Component[] {btnCancelar, btnBorrar});
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	private AbstractAction getAbstractAction1() {
		if(abstractAction1 == null) {
			abstractAction1 = new AbstractAction("Cancelar", null) {
				/**
				 * 
				 */
				private static final long serialVersionUID = 1L;

				public void actionPerformed(ActionEvent evt) {
					dispose();
				}
			};
		}
		return abstractAction1;
	}

	private AbstractAction getAbstractAction2() {
		if(abstractAction2 == null) {
			abstractAction2 = new AbstractAction("Borrar", null) {
				/**
				 * 
				 */
				private static final long serialVersionUID = 1L;

				public void actionPerformed(ActionEvent evt) {
					ControladorAdministradorClientes controlador = new ControladorBorrarClienteFrame();
					controlador.borrarCliente((String)cmbNroCuit.getSelectedItem());
					dispose();
				}
			};
		}
		return abstractAction2;
	}

}
